package com.gitee.wsl.time.calendar.bean

import androidx.compose.runtime.Immutable
import com.gitee.wsl.time.YearMonth
import kotlin.time.ExperimentalTime

/**
 * Represents a month on the calendar.
 *
 * @param yearMonth the calendar month value.
 * @param weekDays the weeks in this month.
 */
@Immutable
data class CalendarMonth @OptIn(ExperimentalTime::class) constructor(
    val yearMonth: YearMonth,
    val weekDays: List<Week>,
)  {
    @OptIn(ExperimentalTime::class)
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (this::class != other!!::class) return false

        other as CalendarMonth

        if (yearMonth != other.yearMonth) return false
        if (weekDays.first() != other.weekDays.first()) return false
        if (weekDays.last() != other.weekDays.last()) return false

        return true
    }

    @OptIn(ExperimentalTime::class)
    override fun hashCode(): Int {
        var result = yearMonth.hashCode()
        result = 31 * result + weekDays.first().hashCode()
        result = 31 * result + weekDays.last().hashCode()
        return result
    }

    @OptIn(ExperimentalTime::class)
    override fun toString(): String {
        return "CalendarMonth { " +
            "yearMonth = $yearMonth, " +
            "firstDay = ${weekDays.first().days.first()}, " +
            "lastDay = ${weekDays.last().days.last()} " +
            "} "
    }
}
